from PyQt4 import QtCore, QtGui
from ui_importgeodexdialog import Ui_GeodexDialog
import geodex

class ImportGeodexDialog(QtGui.QDialog):
    def __init__(self):
        QtGui.QDialog.__init__(self)

        self.ui = Ui_GeodexDialog()
        self.ui.setupUi(self)

        self.connect(self.ui.importPushButton, QtCore.SIGNAL("clicked()"),
                     self.import_geodex)

    def import_geodex(self):
        filename = QtGui.QFileDialog.getOpenFileName(None, "Open File", ".", "GEODEX files (*.fil);;All Files (*.*)")
        output_dir = QtGui.QFileDialog.getExistingDirectory(None, 'Output Directory')
        filename = filename[:-4]

        progress = QtGui.QProgressDialog("Importing records...", "Cancel", 0, 0, None)
        progress.setWindowModality(QtCore.Qt.WindowModal);

        geodex.import_geodex_local(filename,
                                   self.ui.themeLineEdit.text(),
                                   self.ui.geographyLineEdit.text(),
                                   self.ui.subjectLineEdit.text(),
                                   self.ui.authorLineEdit.text(),
                                   self.ui.holdingLineEdit.text(),
                                   self.ui.abstractTextEdit.toPlainText(),
                                   self.ui.purposeTextEdit.toPlainText(),
                                   self.ui.keywordsLineEdit.text(),
                                   str(output_dir),
                                   progress)

        
        

                
